import react from '@vitejs/plugin-react';
import { viteMockServe } from 'vite-plugin-mock';
import { htmlPlugin, pluginImport } from './plugins';

/**
 * 返回对应的插件配置
 * @param publicUrl
 * @returns
 */
export const getPlugins = ({
  publicUrl,
  command,
  mode,
}: {
  publicUrl: string;
  command: string;
  mode: string;
}) => {
  const plugins = [
    htmlPlugin(),
    react(),
    pluginImport({ mode }),
    // doc https://github.com/anncwb/vite-plugin-mock/blob/main/README.zh_CN.md
    viteMockServe({
      mockPath: 'mock',
      watchFiles: true,
      localEnabled: command === 'serve',
      prodEnabled: false,
      logger: true,
    }),
  ];

  return plugins;
};
